﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace iemtm.WeChat.Core.Extension
{
    public static class DataEncryptionExtensions
    {
        /// <summary>
        /// 对字符串进行SHA1加密
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static string ToSHA1Encrypt(this string input)
        {
            try
            {
                byte[] StrRes = Encoding.Default.GetBytes(input);
                HashAlgorithm iSHA = new SHA1CryptoServiceProvider();
                StrRes = iSHA.ComputeHash(StrRes);
                StringBuilder EnText = new StringBuilder();
                foreach (byte iByte in StrRes)
                {
                    EnText.AppendFormat("{0:x2}", iByte);
                }
                return EnText.ToString().ToUpper();

            }
            catch (Exception ex)
            {
                return ex.Message;
            }

        }
    }
}
